<template>
  <div class="page">
    <newPageHeader></newPageHeader>
    <!-- 搜索 -->
    <newSearch></newSearch>

    <div class="data-item" v-if="typeDataShow === true">

      <div v-for="(item, index) in list" :key="index" @click="typeOnchange(item)">
        <div class="typeData">
          <div class="typeImg">
            <img style="width: 100%;height: 100%;" :src="item.image" />
          </div>
          <div class="typeTitle">
            {{ item.title }}
          </div>
        </div>
      </div>
    </div>

    <!-- 类型 -->
    <shoptype ref="shoptype" :itemObj="selectItem" v-if="!typeDataShow" @updateData="updateDataFunc"> </shoptype>



    <div class="stypeShow">


      <div @click="onChangeTap(1)" :class="indexShow === 1 ? 'typeOne' : 'typeTwo'">
        推荐商品
      </div>

      <div @click="onChangeTap(2)" :class="indexShow === 2 ? 'typeOne' : 'typeTwo'">
        推荐商家
      </div>

    </div>



    <ShipData ref="shipData" @updateCount="updateCountFunc"></ShipData>



    <newPageFooter></newPageFooter>
  </div>
</template>
<script>


import { mapState } from "vuex";

import shoptype from './shoptype.vue';


import ShipData from './ShipData.vue';

import newSearch from './newSearch.vue';

import newPageHeader from '../../../components/page/engineering5188/new-page-header.vue';

import newPageFooter from '../../../components/page/engineering5188/new-page-footer.vue';

export default {
  name: "product",
  components: {
    newPageHeader,
    newPageFooter,
    newSearch,
    ShipData,
    shoptype
  },
  computed: {
    ...mapState([
      "userInfo",
    ]),
  },
  data() {
    return {
      typeDataShow: true,
      list: [
      ],
      indexShow: 1,
      selectItem:{},
    };
  },
  created() {
    this.getData();
    console.log(this.userInfo)
  },
  methods: {
    updateCountFunc(count){
      console.log(count, 'dededede3######')
      this.$refs.shoptype.updateCount(count)
    },
    updateDataFunc(query){
      this.$refs.shipData.updateData(query)
    },
    getData() {
      this.list = [];
      this.$httpApi("/api/channelList", {
      }, 'get').then(res => {
        for (let i = 0; i < res.data.length && i < 7; i++) {
          this.list.push(res.data[i])
        }
      })
    },
    typeOnchange(item) {
      console.log(item,'dedede')
      this.selectItem = item;
      this.typeDataShow = false;
      this.updateDataFunc({catid: item.id})
    },

    onChangeTap(num) {
      this.$refs.shipData.setData(num)
      // this.$refs.shipData.dataListShow = num
      this.$nextTick(() => {
        this.indexShow = num
      })


    }
  }
};
</script>

<style scoped lang="less">
.data-item {
  width: 1530px;
  height: 170px;
  margin: auto;
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
}

.stypeShow {
  width: 1530px;
  height: 50px;
  margin: auto;
  display: flex;
  background: #F5F5F5;
  margin-bottom: 20px;
  margin-top: 48px;
}

.typeTwo {
  width: 335px;
  height: 53px;
  background: #F5F5F5;
  font-size: 18px;
  text-align: center;
  line-height: 53px;
  cursor: pointer;
}

.typeOne {
  width: 335px;
  height: 53px;
  background: #FFFFFF;

  border-top: 2px solid blue;
  text-align: center;
  line-height: 53px;

  font-family: PingFang SC, PingFang SC;
  font-weight: 500;
  font-size: 20px;
  color: #005FC9;

  font-style: normal;
  text-transform: none;
  cursor: pointer;

}

.page {
  background-color: #FFFFFF;
}

.typeTitle {

  font-family: PingFang SC, PingFang SC;
  font-weight: 400;
  font-size: 16px;
  color: #000000;
  line-height: 42px;
  text-align: center;
  font-style: normal;
  text-transform: none;
}

.typeImg {
  width: 48px;
  height: 48px;

  margin: auto;
  margin-top: 45px;
}

.typeData {
  width: 170px;
  height: 170px;
  background: #FFFFFF;
  border: 2px solid #EAEAEA;
  border-radius: 50%;
  text-align: center;
  cursor: pointer;
}
</style>